package control.check.data;

import control.options.IConfigObject;
import environment.data.BaseEnvironmentData;
import environment.object.BaseEnvironmentObject;

import java.util.List;

/**
 * Created by vondoom on 05.06.2014.
 */
public class CheckTemperature implements ICheckDataResult,Runnable {

    private IConfigObject config;
    private BaseEnvironmentObject room;
    private ICheckDataListener listener;
    private BaseEnvironmentData.EnvironmentData type;
    private Long value;

    @Override
    public void setCheck(BaseEnvironmentData.EnvironmentData type, Long value, IConfigObject config,BaseEnvironmentObject room,ICheckDataListener listener) {
        this.config = config;
        this.room = room;
        this.listener = listener;
        this.type=type;
        this.value = value;
    }

    @Override
    public void checkForType(BaseEnvironmentData.EnvironmentData type,Long value) {

        switch (type){
            case TEMPERATURE:{
                Long min = config.getListConfigByType(type).get(0);
                Long max = config.getListConfigByType(type).get(1);
                if(value >= max){
                    //data.updateValue(rndValue, BaseEnvironmentData.EnvironmentOptions.MINUS);
                    System.out.println(System.currentTimeMillis()+"| check MINUS ");
                    listener.setCheckResult(room, type, BaseEnvironmentData.EnvironmentOptions.MINUS);
                } else if(value <= min){
                    //data.updateValue(rndValue, BaseEnvironmentData.EnvironmentOptions.PLUS);
                    System.out.println(System.currentTimeMillis()+"| check PLUS ");
                    listener.setCheckResult(room,type, BaseEnvironmentData.EnvironmentOptions.PLUS);
                } else {
                    System.out.println(System.currentTimeMillis()+"| check OK");
                    //listener.setCheckResult(room,type, BaseEnvironmentData.EnvironmentOptions.OK);
                }
                break;
            }
        }
    }

    @Override
    public void run() {
        checkForType(type,value);
    }
}
